package com.demo.pattern.singleton;

/**
 * @author sourire
 * @version 1.0
 * @date 2020/8/17 16:53
 */
public class SingletonTest01 {
    public static void main(String[] args) {
        SingleTon01 instance = SingleTon01.getInstance();
        SingleTon01 instance2 = SingleTon01.getInstance();
        System.out.println(instance == instance2);
        System.out.println("instance === " + instance.hashCode());
        System.out.println("instance2 === " + instance2.hashCode());
    }
}

//静态常量饿汉式

class SingleTon01 {
    //构造器私有化
    private SingleTon01() {
    }
    //在类的内部创建实例
    private final static SingleTon01 instance = new SingleTon01();
    //对外提供静态的调用方法
    public static SingleTon01 getInstance() {
        return instance;
    }
}
